/*
 * data_event.h
 *
 *  Created on: 30.06.2013
 *      Author: SpirTanol
 */

#ifndef DATA_EVENT_H_
#define DATA_EVENT_H_

#include "global.h"
#include "packets/run_config_packet.h"

class DataEvent
{
	DataEventType oType;

public:
	DataEvent(DataEventType type) : oType(type) {}
	virtual ~DataEvent() {}

	inline DataEventType type() const { return oType; }

};

class WatchDataPacket;

class DataEventGet : public DataEvent
{
	WatchDataPacket *oData;

public:
	DataEventGet(const WatchDataPacket *data);
	~DataEventGet();

	inline const WatchDataPacket *data() const { return oData; }

};

class DataEventError : public DataEvent
{
public:
	enum Code
	{
		CONNECT_FAIL,
		OPEN_ERROR,
		LOST_CONNECTION,
		UNEXPECTED_MODIFIER, // Модификация стройства не соответствует ожидаемой
	};

private:
	Code oCode;

public:
	DataEventError(Code code) : DataEvent(DET_ERROR), oCode(code) {}
	~DataEventError() {}

	inline Code code() const { return oCode; }

};

class CrashProtocolPacket;
class ProtocolPacket;

class DataEventGetProtocol : public DataEvent
{
	ProtocolPacket *oEventProtocol;
	CrashProtocolPacket *oCrashProtocol;

public:
	DataEventGetProtocol(const ProtocolPacket *eventProtocol, const CrashProtocolPacket *crashProtocol);
	~DataEventGetProtocol();

	inline const ProtocolPacket *eventProtocol() const { return oEventProtocol; }
	inline const CrashProtocolPacket *crashProtocol() const { return oCrashProtocol; }

};

class ConfigPacket;

enum ConfigEventType
{
	CET_GET,
	CET_SETUP_ERROR,
	CET_SETUPED,
};

class ConfigEvent : public DataEvent
{
	ConfigPacket *oConfig;
	ConfigEventType oType;

public:
	ConfigEvent(const ConfigPacket *packet, ConfigEventType type);
	~ConfigEvent();

	inline const ConfigPacket *config() const { return oConfig; }
	inline ConfigEventType eventType() const { return oType; }

};

class RunConfigPacket;

class RunConfigEventGet : public DataEvent
{
	RunConfigPacket *oRunConfig;

public:
	RunConfigEventGet(const RunConfigPacket *packet);
	~RunConfigEventGet();

	inline const RunConfigPacket *runConfig() const { return oRunConfig; }

};

class RunConfigProgressPacket;

class RunConfigEventProgress : public DataEvent
{
	RunConfigProgressPacket *oProgress;

public:
	RunConfigEventProgress(const RunConfigProgressPacket *packet);
	~RunConfigEventProgress();

	inline const RunConfigProgressPacket *progress() const { return oProgress; }

};

class CrashOscillogramPacket;

class CrashEventOscillogramGet : public DataEvent
{
	CrashOscillogramPacket *oData;

public:
	CrashEventOscillogramGet(const CrashOscillogramPacket *packet);
	~CrashEventOscillogramGet();

	inline const CrashOscillogramPacket *oscillogram() const { return oData; }

};

class ChangeAutoConfigState : public DataEvent
{
	RunConfigProgressPacket::State oOldState;
	RunConfigProgressPacket::State oNewState;

public:
	ChangeAutoConfigState(RunConfigProgressPacket::State oldState, RunConfigProgressPacket::State newState) : DataEvent(DET_CHANGE_AUTO_CONFIG_STATE), oOldState(oldState), oNewState(newState) {}
	~ChangeAutoConfigState() {}

	inline RunConfigProgressPacket::State oldState() const { return oOldState; }
	inline RunConfigProgressPacket::State newState() const { return oNewState; }

};

#endif /* DATA_EVENT_H_ */
